package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class Item {
    public static final int STATE_NORMAL = 0;
    public static final int STATE_PUSH = 1;

    private Long id; // 主键id

    private String name; // 商品名称

    private Integer state = STATE_NORMAL; // 商品状态

    private String imageUrl; // 商品图片

    private Integer reprotety = 0; // 商品库存

    private Integer price; // 商品价格

    private ItemCatalog catalog; //商品所属分类

    private String description; // 商品描述

    private Integer count = 0; // 销量

    private Integer type ; // 商品类型

    private Date inputTime; // 商品入库时间

    //页面数据 回显
    public String getJsonString(){
        Map<String,Object> map  = new HashMap<>();
        map.put("id",id);
        if(catalog != null){
            map.put("catalogId",catalog.getId());
        }
        map.put("name",name);
        map.put("imageUrl",imageUrl);
        map.put("reprotety",reprotety);
        map.put("price",price);
        map.put("description",description);
        map.put("price",price);
        map.put("count",count);
        if(inputTime != null){
            map.put("inputTime", DateUtil.date2string(inputTime,"yyyy-MM-dd"));
        }
        map.put("state",state);
        return JSONUtil.toJSONString(map);
    }


    // 页面状态回显
    public String getStateDisplay(){
        if(state == null){
            return "";
        }
        if(state == STATE_NORMAL){
            return "正常";
        }else if(state == STATE_PUSH){
            return "推荐";
        }
        return "";
    }

}